package functions.ems_payment;

import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



import coms.Constants_zy;
import frame.HttpHelper;
import frame.InterTest;
import functions.ems_claim.FindInitPaymentPreparationByCondition;

public class PayLineReadyDetailController implements InterTest{
	private static Logger logger = LoggerFactory.getLogger(FindInitPaymentPreparationByCondition.class);
	String result;
	String payLineDetailId;
	
	
	
	public PayLineReadyDetailController(String payLineDetailId) {
		super();
		this.payLineDetailId = payLineDetailId;
	}

	/**
	 * 付款准备 明细接口--双击查询付款明细信息
	 */
	public void queryPayLineDetailByPayLineDetailId() {
		logger.info("查询付款明细信息----------------开始");
		String url=Constants_zy.queryPayLineDetailByPayLineDetailIdUrl+payLineDetailId;
		
		try {
			result=HttpHelper.post("", url);
			JSONObject jsonObject=new JSONObject(result);
			logger.info("queryPayLineDetailByPayLineDetailId"+result);
			Integer payLineDetailId=jsonObject.getInt("payLineDetailId");		
			Integer payLineId=jsonObject.getInt("payLineId");		
			Integer batchId=jsonObject.getInt("batchId");
			String payWay=jsonObject.getString("payWay");
			String companyName=jsonObject.getString("companyName");
			String accountName=jsonObject.getString("accountName");
			String accountNo=jsonObject.getString("accountNo");
			String payType=jsonObject.getString("payType");
			String invoiceNo=jsonObject.getString("invoiceNo");
			/*payLineReadyDetailControllerBean=new PayLineReadyDetailControllerBean
					(payLineDetailId, payLineId, batchId, payWay,companyName, accountName,
					accountNo, payType, null, null, null, null, null, null, null,
						null, invoiceNo, null, null, null, null, null);*/
			
				  /*
				  "payLineDetailId": 1,
				  "payLineId": 22,
				  "batchId": 1,
				  "payWay": "1",
				  "companyName": "华润集团",
				  "accountName": "工商银行",
				  "accountNo": "40000",				  
				  "documentConfigFile": "0",
				  "payDocument": "1",
				  "documentType": "F5-12-TODO",
				  "settlementMethod": "102",
				  "remittanceSpeed": "0",  
				  "payType": "0",
				  "fundPlan": "HRZD201703010401",
				  "payTime": "2018-07-19 16:00:00",
				  "vendorAccountNo": "6212260302004365789",
				  "payRequestCompanyName": "王秀林",
				  "vendorCode": "87872387",
				  "vendorName": "张三",
				  "vendorBankId": "x21gd",
				  "vendorSite": "广东深圳",
				  "invoiceNo": "87872387",
				  "cbankCode": "87872387",
				  "vendorAreaCode": "87872387",
				  "isEntrustmentPayment": "YES",
				  "summary": "王亮出差",
				  "purpose": "差旅费"
				  */
				
		} catch (Exception e) {
			e.printStackTrace();
		}
		logger.info("查询付款明细信息---------------------结束");
	}
	/**
	 * 更新付款明细银行信息
	 */
	public void updatePayLineDetailBankInfo() {
		logger.info("更新付款明细银行信息-------------------开始");
		String params="{\"accountName\": \"工商银行\",\"accountNo\": \"40000\","
				+ "\"batchId\": 4000023,\"cbankCode\": \"87872387\","
				+ "\"companyName\": \"华润集团\",\"documentConfigFile\": \"CRC标准付款\","
				+ "\"documentType\": \"付款结算单\",\"fundPlan\": \"TJJGDUGD78278\","
				+ "\"invoiceNo\": \"87872387\",\"isEntrustmentPayment\": \"true\","
				+ "\"payDocument\": \"TMS支票\",\"payLineDetailId\": 3001,"
				+ "\"payLineId\": 4000023,\"payRequestCompanyName\": \"王亮\","
				+ "\"payTime\": \"2018-07-19 16:25:28\",\"payType\": \"1\","
				+ "\"payWay\": \"1\",\"purpose\": \"差旅费\",\"remittanceSpeed\": \"普通\","
				+ "\"settlementMethod\": \"银企直联\",\"summary\": \"王亮出差\","
				+ "\"vendorAccountNo\": \"6212260302004365789\","
				+ "\"vendorAreaCode\": \"87872387\",\"vendorBankId\": \"x21gd\","
				+ "\"vendorCode\": \"87872387\",\"vendorName\": \"张三\","
				+ "\"vendorSite\": \"广东深圳\"}";
		String url=Constants_zy.updatePayLineDetailBankInfoUrl;
		try {
			result=HttpHelper.post(params, url);
			JSONObject jsonObject=new JSONObject(result);
			String status=jsonObject.getString("status");
			if(status.equals("200")) {
				logger.info("更新成功");
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		logger.info("更新付款明细银行信息-------------------结束");
	}



	@Override
	public void run(Map<Object, Object> paramMap) {
		// TODO Auto-generated method stub
	  queryPayLineDetailByPayLineDetailId();
      updatePayLineDetailBankInfo();
	}

  @Override
  public boolean getStatus() {
    // TODO Auto-generated method stub
    return false;
  }

  @Override
  public String getRemark() {
    // TODO Auto-generated method stub
    return null;
  }
}
